#!/bin/sh

########################################################################
# A simple test checking that the core module can be inserted into the 
# kernel and removed from there.
########################################################################

# Just in case the tools like lsmod are not in their usual location.
export PATH=$PATH:/sbin:/bin:/usr/bin

CORE_MODULE="@CORE_MODULE_DIR@/@CORE_MODULE_NAME@.ko"
printf "Core module: ${CORE_MODULE}\n"

if test ! -f "${CORE_MODULE}"; then
    printf "The core module is missing: ${CORE_MODULE}\n"
    
    # test failed
    exit 1
fi

insmod "${CORE_MODULE}" targets="unused"
if test $? -ne 0; then
    printf "Failed to load the core module\n"
    exit 1
fi

rmmod "@CORE_MODULE_NAME@"
if test $? -ne 0; then
    printf "Failed to unload the core module\n"
    exit 1
fi

# test passed
exit 0
